export default class NumeralFormatter {
  groupStyle = {
    thousand: 'thousand',
    lakh: 'lakh',
    wan: 'wan',
    none: 'none'
  }
  constructor (options = {}) {
    let { numeralThousandsGroupStyle, numeralPositiveOnly, delimiter, numeralDecimalMark } = options
    this.numeralThousandsGroupStyle = numeralThousandsGroupStyle || this.groupStyle.thousand // 格式
    this.numeralPositiveOnly = !!numeralPositiveOnly // 正数
    this.delimiter = delimiter || delimiter === '' ? delimiter : ',' // 分隔符
    this.numeralDecimalMark = numeralDecimalMark || '.'
  }
  format (value) {
    value = value
      .replace(/[A-Za-z]/g, '')
      .replace(this.numeralDecimalMark, 'M')
      .replace(/[^\dM-]/g, '')
      .replace(/^-/, 'N')
      .replace(/-/g, '')
      .replace('N', this.numeralPositiveOnly ? '' : '-')
      .replace('M', this.numeralDecimalMark)
    let partSignAndPrefix = value.slice(0, 1) === '-' ? '-' : ''
    let parts // 数组
    let partInteger = value // 正数部分
    let partDecimal = '' // 小数部分
    if (value.indexOf(this.numeralDecimalMark) >= 0) {
      parts = value.split(this.numeralDecimalMark)
      partInteger = parts[0]
      partDecimal = this.numeralDecimalMark + parts[1]
    }

    switch (this.numeralThousandsGroupStyle) {
      case this.groupStyle.thousand:
        partInteger = partInteger.replace(/(\d)(?=(\d{3})+$)/g, '$1' + this.delimiter)
        break
    }
    return partSignAndPrefix + partInteger.toString() + partDecimal.toString()
  }
}

// export const throttle = function (func, wait, options) {
//   let context, args, result
//   // setTimeout 的 handler
//   let timeout = null
//   // 标记时间戳
//   // 上一次执行回调的时间戳
//   let previous = 0
//   // 如果没有传入 options 参数
//   // 则将 options 参数置为空对象
//   if (!options) options = {}

// }
